cmake_minimum_required( VERSION 3.10 FATAL_ERROR )

project( "AngelScript_Dependencies" LANGUAGES CXX )
set_property( GLOBAL PROPERTY USE_FOLDERS ON )

#----------------------------------------------------------------------------------
# settings

set( SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" )
set( AS_NO_EXCEPTIONS OFF CACHE INTERNAL "" FORCE )

set( AE_EXTERNAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../.." )
include( "${AE_EXTERNAL_PATH}/config.cmake" )

#----------------------------------------------------------------------------------
# dependent projects

add_subdirectory( "${SOURCE_PATH}/angelscript/projects/cmake" "angelscript" )
target_compile_definitions( "angelscript" PUBLIC "AS_USE_NAMESPACE=1" )


add_library( "angelscript_stdstring" STATIC
	"${SOURCE_PATH}/add_on/scriptstdstring/scriptstdstring.cpp"
	"${SOURCE_PATH}/add_on/scriptstdstring/scriptstdstring.h"
	"${SOURCE_PATH}/add_on/scriptstdstring/scriptstdstring_utils.cpp"
)
target_include_directories( "angelscript_stdstring" PRIVATE "${SOURCE_PATH}/angelscript/include" )
target_link_libraries( "angelscript_stdstring" PUBLIC "angelscript" )


add_library( "angelscript_scriptarray" STATIC
	"${SOURCE_PATH}/add_on/scriptarray/scriptarray.cpp"
	"${SOURCE_PATH}/add_on/scriptarray/scriptarray.h"
)
target_include_directories( "angelscript_scriptarray" PRIVATE "${SOURCE_PATH}/angelscript/include" )
target_link_libraries( "angelscript_scriptarray" PUBLIC "angelscript" )
target_compile_definitions( "angelscript_scriptarray" PUBLIC "AS_USE_STLNAMES=1" )

if (NOT DEFINED ANDROID)
	set_target_properties( "angelscript" 				PROPERTIES DEBUG_POSTFIX "d" )
	set_target_properties( "angelscript_stdstring" 		PROPERTIES DEBUG_POSTFIX "d" )
	set_target_properties( "angelscript_scriptarray"	PROPERTIES DEBUG_POSTFIX "d" )
endif()

#----------------------------------------------------------------------------------
# install

install( TARGETS "angelscript_stdstring" LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib" )
install( DIRECTORY "${SOURCE_PATH}/add_on/scriptstdstring/" DESTINATION "include" FILES_MATCHING PATTERN "*.h" )

install( TARGETS "angelscript_scriptarray" LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib" )
install( DIRECTORY "${SOURCE_PATH}/add_on/scriptarray/" DESTINATION "include" FILES_MATCHING PATTERN "*.h" )
